﻿
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using Utils;
using PanasonicWarranty.DAL;
namespace PanasonicWarranty.Business
{
    public partial class SmsShortCode
    {
    	#region public properties
		[Required(ErrorMessage="Short Code Required")]
		public string ShortCode { get; set; }
		public string ShortCodeType { get; set; }
		public string MTType { get; set; }
		public bool? Enabled { get; set; }
		public int? OrderID { get; set; }
		#endregion

		#region constructor
		public SmsShortCode(){ }

		public SmsShortCode(IDataReader rd)
		{
			this.ShortCode = rd["ShortCode"].ToString();
			this.ShortCodeType = rd["ShortCodeType"].ToString();
			this.MTType = rd["MTType"].ToString();
			this.Enabled = rd["Enabled"].Equals(DBNull.Value) ? (bool?)null : (bool)rd["Enabled"];
			this.OrderID = rd["OrderID"].Equals(DBNull.Value) ? (int?)null : (int)rd["OrderID"];
		}
		#endregion

		#region private method
        private bool Create()
        {
            return DBSmsShortCode.Create(ShortCode, ShortCodeType, MTType, Enabled, OrderID);
        }

        private bool Update()
        {
            return DBSmsShortCode.Update(ShortCode, ShortCodeType, MTType, Enabled, OrderID);
        }
		#endregion

		#region public method
		public bool Save()
		{
            if(ShortCode != string.Empty)
            {
                return Update();
            }
            else
            {
                return Create();
            }
		}
		#endregion

		#region static method
        public static bool Delete(string ShortCode)
        {
            return DBSmsShortCode.Delete(ShortCode);
        }

        public static List<SmsShortCode> GetAll()
        {
            return ObjectClass.CreateList<SmsShortCode>(DBSmsShortCode.GetAll());
        }

        public static SmsShortCode GetByKey(string ShortCode)
        {
            return ObjectClass.CreateInstance<SmsShortCode>(DBSmsShortCode.GetByKey(ShortCode));
        }

        public static List<SmsShortCode> GetByTop(string top, string where, string order)
        {
            return ObjectClass.CreateList<SmsShortCode>(DBSmsShortCode.GetByTop(top, where, order));
        }
		#endregion
	}
}
